import { Injectable } from '@angular/core';
import { HttpClient } from '../../providers/httpClient';
import { Config } from '../../providers/config';
import { Storage } from '@ionic/storage';

@Injectable()
export class TabsService {
	constructor(
		public httpClient: HttpClient,
		public config: Config,
    private storage: Storage
	) { }

	syncLog(logs) {
		return this.httpClient.post(logs, {
			isShowLoading: false,
			isAlterError: false,
			url: this.config.server + "api/v1/common/log/add",
			isAuthHttp: false
		});
	}

	syncUserStatistics() {
    this.storage.get("UserStatistics").then((UserStatistics) => {
      if (UserStatistics && UserStatistics.length > 0) {
        this.httpClient.post(UserStatistics, {
          isShowLoading: false,
          isAlterError: false,
          url: this.config.server + "api/v1/common/statistics/save"
        }).subscribe(result => {
          if (result) {
            console.log("---------------SaveUserStatistics--------------");
            this.storage.set("UserStatistics", []);
          }
        });
      }
    });
  }
}
